package org.huzhp.service.impl;

import org.huzhp.service.GatewayProperties;
import org.huzhp.service.IHuzhpUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 用户实现类
 * @Author: huzp
 * @CreateDate: 2020/4/3 10:12
 * @Version: 1.0
 */
@Service
public class HuzhpUserServiceImpl implements IHuzhpUserService {

    @Autowired
    private GatewayProperties gatewayProperties;

    @Autowired
    private RestTemplate restTemplate;

    @Override
    public Map findUserByCode(String code) {

        Map user = null;
        try {
            user = restTemplate.getForObject(gatewayProperties.getApi().getFindUserByCode(), Map.class, new HashMap() {{
                put("code", code);
            }});
        } catch (RestClientException e) {
            throw new RuntimeException("调用用户接口【" + gatewayProperties.getApi().getFindUserByCode() + "】出错");
        }

        return user;
    }
}
